<!-- SpecGroup component-->
<template>
  <div>
    <el-row>
      <el-col>
        <el-button type="primary" size="mini" :disabled="!$route.query.enabled"
          >添加分组</el-button
        >
      </el-col>
    </el-row>
    <el-table
      :data="specGroupList"
      style="width: 100%;margin: 10px 0"
      border
      stripe
      :highlight-current-row="true"
    >
      <el-table-column label="序号" type="index" width="80"></el-table-column>
      <el-table-column label="名称" prop="name"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="handleEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row.id)"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="info"
            icon="el-icon-info"
            @click="showSpecParams(scope.row.id)"
            >分组参数</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      specGroupList: [],
      // cid: this.$route.params.cid,
      // enabled: this.$route.params.enabled
      cid: this.$route.query.cid,
      enabled: this.$route.query.enabled
    };
  },

  created() {
    if (this.enabled) {
      this.querySpecGroupListByCid(this.cid);  
    }
    // console.log(this.$route);
    
   },
  // mounted () {
  //   if (this.$route.query.enabled) {
  //     this.querySpecGroupListByCid(this.$route.query.cid);  
  //   }
  // },
  watch: {
    '$route.query.cid': {
      handler(v) {
        // console.log(v);
        this.querySpecGroupListByCid(v)
      },
      // deep: true
    }
  },
  methods: {
    querySpecGroupListByCid(cid) {
      this.$http
        .get(`/spec/group/${cid}`)
        .then((resp) => {
          // console.log(resp);
          if (!resp.flag) {
            this.$message.warn();
            return;
          }
          this.specGroupList = resp.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    handleEdit(item) {},
    handleDelete(id) {},
    showSpecParams(gid) {
      this.$router.push({ name: "specParams", params: { gid } });
    },
  },
};
</script>

<style lang="scss" scoped></style>
